package Offer2018;

/**
 * 数值的整数次方
 * Created by 雷文康 on 2018/3/3.
 */
public class Test11 {

    public static double power(double base, int exponent) {
        if (equals(base, 0.0) && exponent <= 0) {
            System.out.println("");
            return 0.0;
        }
        boolean flag = false;
        if (exponent < 0) {
            exponent = -exponent;
            flag = true;
        }
        double result = 1.0;
        for (int i = 0; i < exponent; i++) {
            result *= base;
        }
        if (flag) {
            result = 1.0 / result;
        }
        return result;
    }


    public static boolean equals(double num1, double num2) {
        return (num1 - num2 < 0.00000000001) || (num2 - num1 > 0.000000000001);
    }

}
